<?php
/* wwwschool project

Copyright (C) 2009  Phillip Aldridge
Email : info@imi21.com
Web site http://www.imi21.com

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/


/**
 *  File : listCoursesStudent.php
 *  called only via ajax 
 *  List all the courses in the table 'course' which this student is enrolled in
 *  @ 
 */  
 
checkSession();

require '../../includes/classes/WS3tableview.php';
require '../../includes/classes/WS3user.php';

$user = new WS3_User(); 
if ($user->setUserID( $id ) )
{

  $table=new WS3_TableView('main',400);
  $table->setTitle( 'Listing Courses for student:'.$user->FullName() );
  //$table->addColumnTH('Course');
  //$table->addColumnTH('Teachers');
  //$table->addColumnTH('Name');
  //$table->addColumnActive(true,'course');
  
  // list student history
if ($session->userType() =='1') $table->addColumn('History','listStudentHistory&amp;student_id='.$user->ID() );

  // list student history
if ($session->userType() =='1') $table->addColumn('Scoring','listStudentScoring&amp;student_id='.$user->ID());

  $table->addColumnDelete(true,'CourseStudent');
  //$table->addColumn('Lessons','listLessons');
  $table->setAlternativeRows(true);
  $table->setInfoRow(true);
  
  $db=new WS3_Database();
  
  $q="SELECT c.id AS cid, c.name, u2c.id
  FROM course AS c, `user2course` AS u2c
  WHERE 1
  AND  c.id = u2c.course_id 
  AND  u2c.user_id = '".$user->ID()."'
  "; // to finish
  
  if ($db->query($q))
  {
    $count = $db->numberRows();
    while ( $db->nextRecord() )
    {
       $table->addRow($db->f('cid'), array(

           'id'=> javaSafeString( $db->f('name') )
        ));
  
    } 
    $table->addToInfoRow("<p>Count = $count </p>");
     echo $table->display();
    $message="Listing";
   
  }else{
    $message="Error : Empty list";
  }


}
/** Get menu */
require '../../includes/menus/topCoursesStudent.php';
$menu=javaSafeString($menu);
echo "document.getElementById('topmenu').innerHTML='$menu';";

echo "document.getElementById('messages').innerHTML='$message';";
if (W3DEBUG)  $debug=new WS3_Debug();

?>
